package cn.yanxiaohui.common.service;

import org.springframework.beans.factory.annotation.Autowired;

import cn.yanxiaohui.common.exception.APIException;
import cn.yanxiaohui.common.mapper.BaseMapper;

/**
 * 业务基类
 * @author yanxh
 */
public abstract class BaseService<M extends BaseMapper<T>, T> {
	
	@Autowired
	private M maper;

	public void insert(T entity) throws APIException {
		maper.insert(entity);
	}

	public void insertSelective(T entity) throws APIException {
		maper.insertSelective(entity);
	}

	public void deleteById(Long id) throws APIException {
		maper.deleteByPrimaryKey(id);
	}

	public void updateById(T entity) throws APIException {
		maper.updateByPrimaryKey(entity);
	}

	public void updateSelectiveById(T entity) throws APIException {
		maper.updateByPrimaryKeySelective(entity);
	}

	public T selectById(Long id) throws APIException {
		return maper.selectByPrimaryKey(id);
	}
}
